package com.congee02.springframework.beans.factory.config;

import com.congee02.springframework.beans.PropertyValues;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * A BeanDefinition describes a bean instance, which has property values,
 * constructor argument values.
 *
 * 一个 BeanDefinition 描述了一个 bean 实例，有其属性值，构造器参数值
 *
 */
@Getter
@Setter
@ToString
public class BeanDefinition {

    String SCOPE_SINGLETON = ConfigurableBeanFactory.SCOPE_SINGLETON;
    String SCOPE_PROTOTYPE = ConfigurableBeanFactory.SCOPE_PROTOTYPE;

    private final Class<?> beanClazz;

    private final PropertyValues propertyValues;

    private String initMethodName;

    private String destroyMethodName;

    private String scope = SCOPE_SINGLETON;

    private boolean singleton = true;

    private boolean prototype = false;

    public BeanDefinition(Class<?> beanClazz) {
        this.beanClazz = beanClazz;
        this.propertyValues = new PropertyValues();
    }

    public BeanDefinition(Class<?> beanClazz, PropertyValues propertyValues) {
        this.beanClazz = beanClazz;
        this.propertyValues = propertyValues;
    }

    public Class<?> getBeanClazz() {
        return beanClazz;
    }

    public PropertyValues getPropertyValues() {
        return propertyValues;
    }

    public void setScope(String scope) {
        this.scope = scope;
        this.singleton = SCOPE_SINGLETON.equals(scope);
        this.prototype = SCOPE_PROTOTYPE.equals(scope);
    }

}
